package homework.test3;

public class Cook extends Thread{
    private final Desk desk;

    public Cook(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true){
            synchronized (desk.getLock()) {
                if(desk.getCount()==0){
                    break;
                }else {
                    if(!desk.isFlag()){
                        System.out.println("厨师正在做汉堡包");
                        desk.setFlag(true);
                        desk.getLock().notifyAll();
                    }else {
                        try {
                            desk.getLock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
